#include "stdafx.h"
#include "WinXPButtonST.h"
#include "resource.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

CWinXPButtonST::CWinXPButtonST()
{
	// No rounded borders
	m_bIsRounded = FALSE;
}

CWinXPButtonST::~CWinXPButtonST()
{
}

// This function is called every time the button border needs to be painted.
// If the button is in standard (not flat) mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
//		[IN]	pDC
//				Pointer to a CDC object that indicates the device context.
//		[IN]	pRect
//				Pointer to a CRect object that indicates the bounds of the
//				area to be painted.
//
// Return value:
//		BTNST_OK
//			Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
{
	return BTNST_OK;
} // End of OnDrawBorder

static void DrawBitmap(CDC* pDC, UINT resID)
{
	CBitmap bmp;
	BOOL b = bmp.LoadBitmap(resID);
	BITMAP bitmap;
	bmp.GetBitmap(&bitmap);
	CDC dc;
	dc.CreateCompatibleDC(NULL);
	dc.SelectObject(&bmp);


	b = pDC->BitBlt(0, 0, bitmap.bmWidth, bitmap.bmHeight, &dc, 0, 0, SRCCOPY);
}

// This function is called every time the button background needs to be painted.
// If the button is in transparent mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
//		[IN]	pDC
//				Pointer to a CDC object that indicates the device context.
//		[IN]	pRect
//				Pointer to a CRect object that indicates the bounds of the
//				area to be painted.
//
// Return value:
//		BTNST_OK
//			Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)
{

	if (m_bIsPressed)
	{
		DrawBitmap(pDC,IDB_BUTTON_MAIN_DOWN);
	}
	else if (m_bMouseOnButton)
	{
		DrawBitmap(pDC,IDB_BUTTON_MAIN_IN);
	}
	else
	{
		DrawBitmap(pDC,IDB_BUTTON_MAIN_OUT);
	}

	return BTNST_OK;


} // End of OnDrawBackground

// This function enables or disables the rounded border for the button.
//
// Parameters:
//		[IN]	bRounded
//				If TRUE the button will have a round border.
//		[IN]	bRepaint
//				If TRUE the button will be repainted.
//
// Return value:
//		BTNST_OK
//			Function executed successfully.
//
DWORD CWinXPButtonST::SetRounded(BOOL bRounded, BOOL bRepaint)
{
	m_bIsRounded = bRounded;
	if (bRepaint)	Invalidate();

	return BTNST_OK;
} // End of SetRounded

void CWinXPButtonST::DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled)
{
	rpCaption->OffsetRect(1,1);
	pDC->SetTextColor(RGB(255,255,255));
	pDC->DrawText(lpszText, -1, rpCaption, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

	rpCaption->OffsetRect(-1,-1);
	pDC->SetTextColor(RGB(0,0,0));
	pDC->DrawText(lpszText, -1, rpCaption, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

}